package com.chen.qq;

import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.geom.Arc2D;

/**
 * @author 5
 * 
 */
public class TranslatePolicy implements TransformPolicy {

	public static final int I2O = 0;
	public static final int O2I = 1;

	private boolean transparent = false;

	public static final int Center = 10;
	public static final int LeftTop = 11;
	public static final int RightTop = 12;
	public static final int LeftBottom = 13;
	public static final int RightBottom = 14;
	public static final int Clock = 15;

	private int start = 0;

	@Override
	public boolean transform(Graphics2D g1, Graphics2D g2, float ratio, float width, float height) {
		if (transparent) {
			AlphaComposite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, ratio);
			g1.setComposite(c);
			g2.setComposite(c.derive(1 - ratio));
		}

		if (start == I2O) {
			g1.translate(width * (1 - ratio) / 2, height * (1 - ratio) / 2);
			g1.scale(ratio, ratio);
		} else if (start == O2I) {
			g2.translate(width * ratio / 2, height * ratio / 2);
			g2.scale(1 - ratio, 1 - ratio);
			return false;
		} else if (start == Center) {
			g2.scale(1 - ratio, 1 - ratio);
			g2.translate(width * ratio / 2, height * ratio / 2);
			return false;
		} else if (start == LeftTop) {
			g2.translate(-width * ratio, -height * ratio);
			return false;
		} else if (start == RightTop) {
			g2.translate(width * ratio, -height * ratio);
			return false;
		} else if (start == LeftBottom) {
			g2.translate(-width * ratio, height * ratio);
			return false;
		} else if (start == RightBottom) {
			g2.translate(width * ratio, height * ratio);
			return false;
		} else if (start == Clock) {
			float d = Math.max(width, height);
			g2.clip(new Arc2D.Float(0, 0, d, d, 90, 360 * (1 - ratio), Arc2D.PIE));
			return false;
		}

		return true;
	}
}
